﻿// Written by Shai Raiten: http://tinyurl.com/shai-rai
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Xml;
using System.Collections.Generic;

namespace Fart7
{
    public class XmlCommands
    {
        private XmlReader reader;        
        private const string XmlPath = "DataSource/FartsDataSource.xml";

        public XmlCommands()
        {
            reader = XmlReader.Create(XmlPath);
        }

        public List<Fart> GetFarts()
        {
            List<Fart> list = new List<Fart>();
            while (reader.Read())
            {
                
                if (reader.NodeType == XmlNodeType.Element && reader.Name =="Fart")
                {                                  
                    if (reader.HasAttributes)
                    {
                        Fart f = new Fart();
                        f.Name = reader.GetAttribute("Name");
                        f.Uri = new Uri(reader.GetAttribute("Uri"));
                        f.Duration = reader.GetAttribute("Duration");
                        f.Format = reader.GetAttribute("Format");
                        list.Add(f);
                    }
                }
            }

            return list;
        }
    }
}
